package com.suyujia.swagger_demo1.config;

import org.springframework.boot.context.config.Profiles;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
//开启Swagger2
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket(Environment environment){
//        Profiles profiles = Profiles.of("dev");
        //获取项目的环境
//        environment.getActiveProfiles()
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //RequestHandlerSelectors,用来配置要扫描借口的方式
                //basePackage:基于所选择的包进行扫描
                //any():扫描全部
                //none()不扫描
                //withClassAnnotation()基于注解进行扫描，比如withClassAnnotation(RequestMapping.class),
                // 那他就会扫描所有被注解了@QequestMapping的类
                .apis(RequestHandlerSelectors.basePackage("com.suyujia.swagger_demo1.controller"))//意思是基于某个包进行扫描
                //过滤路径
                //PathSelectors的参数有：ant()--》路径,any()--》任何,none()--》拒绝,regex()--》正则
                //eg：PathSelectors.ant(/suyujia/**)
                //只会匹配以/suyujia/ 为开头的链接
//                .paths(PathSelectors.ant("/suyujia/**"))
                .build();
    }

    private ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("suyujia", "https://www.bilibili.com/", "1747766732@qq.com");
        return new ApiInfo("SwaggerApi文档",//标题
                "苏煜佳的SwaggerApi文档",//文本描述
                "1.0",//版本号
                "urn:tos",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
